/**
 * @param {string} s
 * @return {string}
 */
var reverseVowels = function(s) {
  let position = new Array(s.length).fill(false), temp = "";
  function isVowel(alpha) {
    alpha = alpha.toLowerCase()
    switch(alpha) {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
        return true;
      default:
        return false;
    }
  }
  for(let i = 0; i < s.length; i++) {
    if(isVowel(s[i])) {
      position[i] = true;
      temp += s[i];
    }
  }
  temp = temp.split("").reverse();
  let count = 0;
  s = s.split("");
  for(let i = 0; i < s.length; i++) {
    if(position[i]) {
      s[i] = temp[count];
      count++;
    }
  }
  return s.join("");
};
let s = "hello";
console.log(reverseVowels(s));
s = "leetcode";
console.log(reverseVowels(s));
